import { MutationRes } from 'src/modules/shared/vo/mutation.res';
import { AccountService } from '../../services/account/account.service';
import { Resolver, Query, Args, Mutation } from '@nestjs/graphql';
import { AccountEntity } from '../../entities/account.entity';
import {ModifyAccountInput} from '../dto/modifyAccount.input';

@Resolver('Account')
export class AccountResolver {
    constructor (
        private readonly accountService: AccountService,
    ) { }

    @Query(() => [AccountEntity!]!, { description: '查询全部的账号' })
    async accountList(): Promise<AccountEntity[]> {
        return await this.accountService.accountList();
    }

    @Query(() => AccountEntity!, { description: '根据账号id查询账号信息' })
    async account(
        @Args('id') id: number,
    ): Promise<AccountEntity> {
        return await this.accountService.account(id);
    }

    @Mutation(() => MutationRes, { name: 'createAccount', description: '创建账号' })
    async createAccount(
        @Args('username') username: string,
        @Args('password') password: string,
    ): Promise<MutationRes> {
        return await this.accountService.createAccount(username, password);
    }

    @Mutation(() => MutationRes, { nullable: false, name: 'modifyAccountById', description: '根据id修改数据' })
    async modifyAccountById(
        @Args('id') id: number,
        @Args('data') modifyAccountInput: ModifyAccountInput,
    ): Promise<MutationRes> {
        return await this.accountService.modifyAccountById(id, modifyAccountInput);
    }

    @Mutation(() => MutationRes, { description: '根据id删除账号' })
    async deleteAccountById(
        @Args('id') id: number
    ): Promise<MutationRes> {
        return await this.accountService.deleteAccountById(id);
    }
}
